package com.xc.controller.backend;

import com.sun.java.swing.plaf.gtk.GTKConstants;
import com.xc.common.Const;
import com.xc.common.ServerResponse;
import com.xc.service.IUserPositionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;

/**
 * @author mipha
 * @version 1.0
 * @date 2019/2/28 11:01 AM
 */
@Controller
@RequestMapping("/admin/position/")
@Slf4j
public class AdminPositionController {

    @Autowired
    IUserPositionService iUserPositionService;

    /**
     *      管理员持仓列表
     * @param agentId
     * @param positionType
     * @param state
     * @param userId
     * @param positionSn
     * @param beginTime
     * @param endTime
     * @param pageNum
     * @param pageSize
     * @param request
     * @return
     */
    @RequestMapping("list.do")
    @ResponseBody
    public ServerResponse list(
            @RequestParam(value = "agentId",required = false) Integer agentId
            ,@RequestParam(value = "positionType", required = false) Integer positionType
            ,@RequestParam(value = "state", required = false) Integer state
            ,@RequestParam(value = "userId", required = false) Integer userId
            ,@RequestParam(value = "positionSn", required = false) String positionSn
            ,@RequestParam(value = "beginTime", required = false) String beginTime
            ,@RequestParam(value = "endTime", required = false) String endTime
            , @RequestParam(value = "pageNum", defaultValue = "1") int pageNum
            , @RequestParam(value = "pageSize", defaultValue = "12") int pageSize
            , HttpServletRequest request){
        return iUserPositionService.listByAdmin(agentId,positionType
                ,state,userId,positionSn,beginTime,endTime,pageNum,pageSize);
    }

    /**
     *  管理员强制平仓
     * @param positionSn
     * @return
     * @throws Exception
     */
    @RequestMapping("sell.do")
    @ResponseBody
    public ServerResponse sell(String positionSn) throws Exception{
        ServerResponse serverResponse = null;
        try {
            serverResponse = iUserPositionService.sell(positionSn, Const.SellStockDoType.admin_do_type);
        }catch (Exception e){
            log.error("强制平仓 异常信息 = {}" , e);
        }
        return serverResponse;
    }

    /**
     *  管理员锁仓
     * @param positionId
     * @param state
     * @param lockMsg
     * @return
     */
    @RequestMapping("lock.do")
    @ResponseBody
    public ServerResponse lock(@RequestParam(value = "positionId") Integer positionId
            ,@RequestParam(value = "state") Integer state
            ,@RequestParam(value = "lockMsg" ,required = false) String lockMsg
    ){
        return iUserPositionService.lock(positionId,state,lockMsg);
    }


    /**
     *  删除
     * @param positionId
     * @return
     */
    @RequestMapping("del.do")
    @ResponseBody
    public ServerResponse del(@RequestParam(value = "positionId") Integer positionId){
        return iUserPositionService.del(positionId);
    }



}
